package com.icinfo.cloud.provider.punish.common.nonlitigation.enums;

import lombok.Getter;
import org.springframework.util.ObjectUtils;

/**
 * 描述：非诉执行当事人类别枚举
 *
 * @author shishengyao
 * @description
 * @date 2022/4/9
 */
public enum NonLitigationPartyTypeEnum {
    /**
     * 非诉执行当事人类别枚举
     */
    PERSON("15_000004-1", "个人", "1"),
    LEGAL("15_000004-2", "法人", "2"),
    NON_LEGAL("15_000004-3", "非法人组织", "");

    /**
     * 编码
     */
    @Getter
    private String code;
    /**
     * 描述
     */
    @Getter
    private String des;
    /**
     * 关联code
     */
    @Getter
    private String relCode;

    NonLitigationPartyTypeEnum(String code, String des, String relCode) {
        this.code = code;
        this.des = des;
        this.relCode = relCode;
    }

    /**
     * 描述：根据relCode获取code
     *
     * @param relCode rel代码
     * @return {@link String }
     * @author shishengyao
     * @date 2022/04/09
     */
    public static String getCodeByRelCode(String relCode) {
        if (ObjectUtils.isEmpty(relCode)) {
            return null;
        }
        for (NonLitigationPartyTypeEnum e : NonLitigationPartyTypeEnum.values()) {
            if (relCode.equals(e.getRelCode())) {
                return e.getCode();
            }
        }
        return relCode;
    }

    /**
     * 描述：根据code获取value
     *
     * @param code 编码
     * @return 描述内容
     * @author xiangyuyu
     * @date 2022-02-22 10:43
     */
    public static String getValueByCode(String code) {
        if (ObjectUtils.isEmpty(code)) {
            return null;
        }
        for (NonLitigationPartyTypeEnum e : NonLitigationPartyTypeEnum.values()) {
            if (code.equals(e.getCode())) {
                return e.getDes();
            }
        }
        return code;
    }

    /**
     * 描述：校验code是否是合法枚举
     *
     * @param code 枚举code
     * @return boolean 是否合法枚举（true-是/false-否）
     * @author xiangyuyu
     * @date 2022-02-22 10:42
     */
    public static boolean isLegalEnumCode(String code) {
        boolean flag = false;
        for (NonLitigationPartyTypeEnum e : NonLitigationPartyTypeEnum.values()) {
            if (e.getCode().equalsIgnoreCase(code)) {
                flag = true;
                break;
            }
        }
        return flag;
    }
}
